let viewCommend = (function () {
    let html = '';
    let tpl = {
        product({src, text}) {
            return `
            <div>
                <img src=${src}/>
                <p>${text}</p>
            </div>
        `
        },
        title({title, tips}) {
            return `<div class="title">
                <div class="main">
                    <h2>${title}</h2>
                    <p>${tips}</p>
                </div>
            </div>
        `
        }
    };
    let Action = {
        create(data, view){
            if (data.length) {
                for(let i = 0; i < data.length; i++) {
                    html += tpl[view](data[i]);
                }
            }else{
                html += tpl[view](data);
            }
        },
        display(container, data, view){
            if(data) {
                this.create(data, view);
            }
            document.getElementById(container).innerHTML = html;
            html = '';
        }
    };
    return function excute(msg) {
        msg.param = Object.prototype.toString.call(msg.param) === '[object Array]' ? msg.param : [msg.param];
        Action[msg.command].apply(Action, msg.param);
    }
})();

let productData = [
    {
        src: '02.jpg',
        text: '绽放的桃花'
    },{
        src: '03.jpg',
        text: '阳光下的温馨'
    },{
        src: '04.jpg',
        text: '镜头前的绿色'
    },
],
titleData = {
    title: '夏日里的一片温馨',
    tips: '暖暖的温情带给人们家的感受。'
};
viewCommend({
    command: 'display',
    param: ['title', titleData, 'title']
});
viewCommend({
    command: 'display',
    param: ['product', productData, 'product']
});